Display `pretty output` of directory content from array
Posted
by user275074
on Stack Overflow
See other posts from Stack Overflow
or by user275074
Published on 2010-03-23T11:58:35Z
Indexed on
2010/03/23
13:23 UTC
Read the original article
Hit count: 277
Hi,
I'm using the following code to get an array of directories and their sub-directories where each contain file type extension: png. It works great but I need to be able to output the results of the array in a list style format e.g.
- Test
-> test2.png
-> test1.png
- subfolder -> test3.png
- sub sub folder -> test4.png
etc
Code:
$filter=".png";
$directory='../test';
$it=new RecursiveDirectoryIterator("$directory");
foreach(new RecursiveIteratorIterator($it) as $file){
if(!((strpos(strtolower($file),$filter))===false)||empty($filter)){
$items[]=preg_replace("#\\\#", "/", $file);
}
}
Example array of results:
array (
0 => '../test/test2.png',
1 => '../test/subfolder/subsubfolder/test3.png',
2 => '../test/subfolder/test3.png',
3 => '../test/test1.png',
)
What would be the best way of achieving the desired result?
© Stack Overflow or respective owner